var queryParam = null;
$(function(){
    laydate.skin('yahui');//切换皮肤，请查看skins下面皮肤库
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
        // start: '2014-6-15',
        // min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16', //最大日期
        istime: true,
        istoday: false,
        choose: function(datas){
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
        max: '2099-06-16',
        event: 'click',
        istime: true,
        istoday: false,
        choose: function(datas){
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    queryParam = null;
    laydate(start);
    laydate(end);

    $('#start').val(laydate.now(-30, 'YYYY-MM-DD'));
    $('#end').val(laydate.now(0, 'YYYY-MM-DD'));
    getBusinessProfession("bizUserType");
    queryPageList();
});

function queryPageList() {
    queryParam = {"flag" : "admin","status" : -100};
    var obj = $(".controlDiv").serializeSearchForm();
    queryParam = $.extend(queryParam,obj);
    goPage(1);
}

function getListPage(param){
    param = $.extend(queryParam,param);
    $.ajax({
        type : "post",
        url : "htmlWeb/getExamplePageList",//,"payStatus" : -2
        data: param,
        async: false,
        success : function(data){
            $("#examplePageHead ~ tr").remove();
            var str = "";
            $.each(data.rows,function(i,obj){
                obj = trimEmpty(obj);
                var status = renderExampleStatus(obj.status);
                var exampleType = renderExampleType(obj.exampleType);
                var mobile = obj.userInfoBvo.mobile == 'admin' ? "" : obj.userInfoBvo.mobile;
                str += '<tr><td><p>' + obj.id + '</p></td>' +
                    '<td><p>' + obj.userInfoBvo.cnName + '</p></td>' +
                    '<td><p>' + mobile + '</p></td>' +
                    '<td><p>' + obj.caseTime + '</p></td>' +
                    '<td><p>' + obj.userInfoBvo.bizWork.name + '</p></td>' +
                    '<td><p>' + obj.userInfoBvo.province + '</p></td>' +
                    '<td><p>' + obj.userInfoBvo.city + '</p></td>' +
                    '<td><p>' + obj.userInfoBvo.area + '</p></td>' +
                    '<td><p>' + exampleType + '</p></td>' +
                    '<td><span>' + obj.name + '</span></td>' +
                    '<td><p><img src="http://img.boyitongcheng.com/' + obj.imgUrl + '" width="80px" height="60px"></p></td>' +
                    '<td><span>' + status + '</span></td>' +
                    '<td><span class="userSpan"><a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',-2)">删除</a>';
                if(obj.status == -1){
                    str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',1)">审核通过</a>';
                    str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',4)">审核不通过</a>';
                }else if(obj.status == 4){
                    str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',1)">审核通过</a>';
                }else if(obj.status == 2){
                    str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',5)">推荐</a>';
                }
                // else if(obj.status == 1){
                //     str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',2)">上架</a>';
                //     str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',3)">下架</a>';
                // }else if(obj.status == 2){
                //     str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',3)">下架</a>';
                // }else if(obj.status == 3){
                //     str += '<a class="cur" href="javascript:void(0);" onclick="updateStatus('+ obj.id + ',2)">上架</a>';
                // }
                str += '</span></td></tr>';
            });
            $("#examplePageHead").after(str);
            createPage(data);

        },
        error : function(data){
            console.log(data);
        }
    });
}

function updateStatus(id,status) {
    $.post("/htmlWeb/updateExampleView",{"id" : id,"status" : status},function(){
        tip("操作成功");
        queryPageList();
    });
}

function deleteWork(){
    tip("删除成功");
}

function showCaseList() {
    navPills("/htmlWeb/systemCaseListHtml");
}